# __author__ = 'heyin'
# __date__ = '2018/11/20 14:27'
import pandas as pd
import numpy as np

# 生成一段时间序列，结果中包含start和end的值
# d = pd.date_range(start='20181101', end='20191101')
# d = pd.date_range(start='2018-11-01', end='2018-12-01')
# d = pd.date_range(start='2018/11/01', end='2018/12/01')
# d = pd.date_range(start='11/01/2018', end='12/01/2018')
# 以上格式全都支持
# print(d)
# print(len(d))
# print(d.shape)
#
# d = pd.date_range(start='20171130', end='20181129', freq='M')
# print(d)
#
# d = pd.date_range(start='20171130', end='20181129', freq='3M')
# print(d)


# d = pd.read_csv('./911.csv')
# print(d.head(4))
# print(d.dtypes)
# print(d.index)
# print(d['timeStamp'])
#
# s = pd.to_datetime(d['timeStamp'])
# print(s)


# 重采样
t = pd.DataFrame(np.random.uniform(10, 50, (100, 1)), index=pd.date_range('20180101', periods=100, freq='D'))
# print(t)
# 按月重采样
t= t.resample('M')
print(t)  # 返回DatetimeIndexResampler对象

print(t.mean())
print(t.count())

df = pd.read_csv('./BeijingPM20100101_20151231.csv')
period = pd.PeriodIndex(year=df["year"],month=df["month"],day=df["day"],hour=df["hour"],freq="H")
print(period)